<template>
    <el-dialog :title="title" v-model="dialogVisible" top="20px" width="1050px">
        <el-main class="nopadding">
            
        </el-main>

        <template #footer>
            <el-button plain @click="dialogVisible = false">关闭</el-button>
            <el-button plain type="primary" :loading="loading" @click="save">保存</el-button>
        </template>
    </el-dialog>
</template>

<script setup>
import api from '@/api'
import { ref } from 'vue'
import { tool } from "@/moduleExport"

const emit = defineEmits(['reload'])
const dialogVisible = ref(false)
const title = ref('')
const formData = ref({})

const getColumn = () => {
    return [
        { name: 'name1', label: 'label1' },
        { name: 'name2', label: 'label2' }
    ]
}

const onSelect = (data) => {
    formData.value.workOrderId = data.id
}

const open = (id) => {
    // formData初始化
    formData.value = {
        goodsNo: '',
    }
    if (id) {
        api.getById(id).then(res => {
            formData.value = res
        })
    } else {
        title.value = '添加'
    }
    dialogVisible.value = true
}

const loading = ref(false)
const save = () => {
    loading.value = true
    api.save(formData.value).then(res => {
        emit('reload')
        tool().notify.success("保存成功")
        dialogVisible.value = false
    }).finally(() => {
        loading.value = false
    })
}

defineExpose({ open })
</script>

<style lang="scss" scoped>
.el-form-item {
    margin-right: 17px;
}
.el-input--default {
    width: 210px;
}
</style>